/**
 * Created by vincent on 2017/9/12.
 */
moduleStudyMap.controller("AddStudyMapController", function ($$CambioConfig, $scope, $log, $state, LoadingService,
                                                             UploadFileService, ConstantService, StudyMapResource, DialogService) {
    $scope.$on("ngDialog.opened", function () {
        dialogOnLoad();
    });

    $scope.newStudyMap = {};

    /**
     * 上传图片
     * @param $files
     */
    $scope.uploadImage = function ($files) {
        if ($files && $files[0]) {
            UploadFileService.uploadFile($files[0], $$CambioConfig.UPLOAD_URL, 'IMG', $scope).then(function (o) {
                $scope.newStudyMap.picture = o.id;
            });
        }
    };

    $scope.cancel = function () {
        DialogService.close();
    };

    $scope.submit = function () {
        if ($scope.addSMForm.$valid) {
            //LoadingService.show();
            StudyMapResource.add($scope.newStudyMap, function (studyMapResult) {
                $log.debug("学习地图新增结果", studyMapResult);
                DialogService.close();
                Alert.success("新增学习地图成功！");
                //LoadingService.hide();
            });
        }
    };

});